package com.study.scala

import scala.collection.mutable.ArrayBuffer

object ArrayDemo {

  def main(args: Array[String]): Unit = {
    // 数组
    val a = new Array[String](5)
    a(0) = "a"

    val b = Array("a", "b", "c")
    println(b.max)

    val c = Array(1, 2, 3, 4, 5)
    println(c.mkString(","))
    println(c.mkString("#", ",", "&"))

    // 可变数组
    val d = ArrayBuffer[Int]()
    d += 1
    d += (2, 3, 4)
    d ++= Array(5, 6, 7)
    d.insert(0, 0)
    d.remove(4, 1)
    d.trimEnd(2)
    println(d)
    println(d.toArray.mkString)

    for (ele <- d)
      println(ele)

    println("======================================")

    for (i <- (0 until d.length).reverse)
      println(d(i))
  }
}
